//
//  ZJVideoControllerMeunView.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/10.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJVideoControllerMeunView.h"

@interface ZJVideoControllerMeunView ()


@end

@implementation ZJVideoControllerMeunView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.startButton];
        [self addSubview:self.speed];
        [self addSubview:self.backward];
        [self addSubview:self.currentTime];
        [self addSubview:self.totalTime];
        
        self.currentTime.sd_layout
        .topSpaceToView(self, 8 * [UIScreen zj_screenHScale])
        .bottomSpaceToView(self, 8 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .widthIs(70 * [UIScreen zj_screenWScale]);
        
        self.totalTime.sd_layout
        .topSpaceToView(self, 0)
        .bottomSpaceToView(self, 0)
        .rightSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .widthIs(70 * [UIScreen zj_screenWScale]);
        
        self.startButton.sd_layout
        .topEqualToView(self.currentTime)
        .bottomEqualToView(self.currentTime)
        .widthIs(80 * [UIScreen zj_screenWScale])
        .centerXEqualToView(self);
        
        self.backward.sd_layout
        .topEqualToView(self.currentTime)
        .bottomEqualToView(self.currentTime)
        .leftSpaceToView(self.currentTime, 0)
        .rightSpaceToView(self.startButton, 0);
        
        self.speed.sd_layout
        .topEqualToView(self.currentTime)
        .bottomEqualToView(self.currentTime)
        .leftSpaceToView(self.startButton, 0)
        .rightSpaceToView(self.totalTime, 0);
        
        UILabel *underLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.height - 1, self.width, 1)];
        underLabel.backgroundColor = [UIColor zj_colorWithHexString:@"dedede"];
        [self addSubview:underLabel];
        
    }
    return self;
}


#pragma mark - 点击事件
- (void)action_StartButton:(UIButton *)button{
    button.selected = !button.selected;
    if ([self.delegate respondsToSelector:@selector(ZJVideoControllerMeunViewDelegate_startButton:)]) {
        [self.delegate ZJVideoControllerMeunViewDelegate_startButton:button];
    }
}
//快进
- (void)action_speed:(UIButton *)button{
    if ([self.delegate respondsToSelector:@selector(ZJVideoControllerMeunViewDelegate_speed:)]) {
        [self.delegate ZJVideoControllerMeunViewDelegate_speed:button];
    }
}
//快退
- (void)action_backward:(UIButton *)button{
    if ([self.delegate respondsToSelector:@selector(ZJVideoControllerMeunViewDelegate_backward:)]) {
        [self.delegate ZJVideoControllerMeunViewDelegate_backward:button];
    }
}



#pragma mark - Setter


#pragma mark - Getters
- (UILabel *)currentTime{
    if (_currentTime == nil){
        _currentTime = [UILabel new];
        _currentTime.textColor = [UIColor textGrayColor];
        _currentTime.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
        _currentTime.text = @"00:00:00";
    }
    return _currentTime;
}
- (UILabel *)totalTime{
    if (_totalTime == nil){
        _totalTime = [UILabel new];
        _totalTime.textColor = [UIColor textGrayColor];
        _totalTime.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
        _totalTime.textAlignment = NSTextAlignmentRight;
        _totalTime.text = @"00:00:00";
    }
    return _totalTime;
}

- (UIButton *)startButton{
    if (_startButton == nil){
        _startButton = [[UIButton alloc]init];
        [_startButton setImage:[UIImage imageNamed:@"learn_play"] forState:UIControlStateNormal];
        [_startButton setImage:[UIImage imageNamed:@"learn_stop"] forState:UIControlStateSelected];
        [_startButton addTarget:self action:@selector(action_StartButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _startButton;
}
- (UIButton *)speed{
    if (_speed == nil){
        _speed = [[UIButton alloc]init];
        [_speed setImage:[UIImage imageNamed:@"learn_backword"] forState:UIControlStateNormal];
        [_speed addTarget:self action:@selector(action_speed:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _speed;
}
- (UIButton *)backward{
    if (_backward == nil){
        _backward = [[UIButton alloc]init];
        [_backward setImage:[UIImage imageNamed:@"learn_forword"] forState:UIControlStateNormal];
        [_backward addTarget:self action:@selector(action_backward:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _backward;
}
@end
